package com.hjl.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.Date;

/**
 * @author ServivE
 * @version 0.1
 * @className MyServletContextListener
 * @description
 * @date 2024/7/26 19:27
 * @since jdk11
 */
//监听服务器的开启与停止
    //监听ServletContext域的创建与销毁的监听器ServletContextListener（较常用）
public class MyServletContextListener  implements ServletContextListener {
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("启动时间," + new Date().toLocaleString());
        System.out.println("应用名称，" + sce.getServletContext().getContextPath());
    }

    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        System.out.println("服务停止时间，" + new Date().toLocaleString());
    }
}
